<template>
    <view>
        <tn-navbar> 修改车位</tn-navbar>
        <view class="tn-m-sm tn-p-sm shadow"> 
            <view class="tn-mb">
                <tn-title title="车场名称"  mode="vLine" assist-color="tn-blue" size="lg" /></view>
                <tn-form ref="formRef" :model="formData"   label-position="top">
                    <tn-form-item label="总车位数">
                        <tn-input v-model="formData.totalNum"  ></tn-input>
                    </tn-form-item>
                    <tn-form-item label="已用车位数">
                        <tn-input v-model="formData.usedNum"></tn-input>
                    </tn-form-item> 
                    <view class="tn-flex justify-center">
                        
                        <tn-button @click="updateCarParkSpaceNumber" size="xl" width="100%">确认</tn-button>
                    </view>
                </tn-form>
            </view>
    </view>

</template>

<script setup lang="ts">
import { onMounted ,ref } from "vue";
import {onLoad} from "@dcloudio/uni-app";
import CfCarParkUtil from "@/cfsheep/api/cfCarPark/park";
const formData = ref({
    id: 0,
    totalNum: 0,
    usedNum: 0,
});
const carParkId = ref(0);
const carParkInfo = ref({
  address: "",
  adminer: "",
  advanceSubscribeTime: "0",
  allowEditUseLog: 0,
  autoIssuedWhitelist: 0,
  billingModel: "dynamic_time",
  chargingStationId: "",
  checkRepeatTime: "300000",
  cleanNotPayLimit: "0",
  collectionCarparkId: "0",
  confirmPassage: 0,
  countryId: "",
  createrId: "1724672270691020800",
  currentFeeUpperLimit: 0,
  currentGroupFlag: '',
  currentPrice: 3,
  distance: 0,
  enableDeactivatePackage: 0,
  enableStoredCard: 0,
  envControlEndTime: "0",
  envControlLevel: "",
  envControlResponseLevel: "",
  envControlStartTime: "0",
  envControlStrategy: "",
  environmentalControl: 0,
  etcApplicationId: "1798615590504517632",
  etcParkId: "PK24079035",
  expiredCarFreeTime: "0",
  feeUnit: 0,
  feeUpperLimit: 9999,
  forbidGroupFlagSameTimeIn: 0,
  freeTime: "900000",
  id: "1730411188979781632",
  image: "",
  imageUrl: null,
  landline: "",
  leaveTimeLimit: "900000",
  limitParkingSpaceNumber: 0,
  name: "星悦国际",
  numberOfComments: 0,
  numberPlateColorToCarType: 0,
  packageExpirationNotice: 0,
  packageGroupFlagAutoChange: 1,
  parkingSpaceNumber: 2000,
  parkingSpaceNumberCount: null,
  phone: "",
  positionX: 0.00,
  positionY: 0.00,
  provinceId: "",
  recognitionSpecialVehicles: 0,
  recovery: 0,
  reportedData: 0,
  scheduledVisitsEffectiveTime: 86400000,
  score: 0,
  sellingPackage: 0,
  showExpiredCarType: 0,
  showRemarks: 1,
  specialFeeExpiredCar: 0,
  specialNumberPlate: "",
  startingPrice: 0,
  stateOrCityId: "",
  status: 0,
  storehouseId: "0",
  strandedVehiclesDefinedTime: "2592000000",
  subscribeFee: 0,
  subscribeFreeTime: "0",
  subscribeTimeoutFee: 0,
  townshipId: "",
  unitDuration: "1200000",
  useEtc: 1,
  usedParkingSpaceNumber: 1252,
  usedParkingSpaceNumberCount: 0,
  visitProcessMode: 0,
  wxMpAppid: "",
  zoneOrCountyId: ""
});

/**
 * 拉取车场信息
 */
const getCarParkInfo = async () => {
  const _carParkInfo = await CfCarParkUtil.getCarParkInfoById({
    carParkId: carParkId.value
  });
  if(_carParkInfo.code == 10002){
    carParkInfo.value = _carParkInfo.data;
    formData.value.totalNum = carParkInfo.value.parkingSpaceNumber
    formData.value.usedNum = carParkInfo.value.usedParkingSpaceNumber
  }else{
    carParkInfo.value = {};
  }
};

/**
 * 更新车场车位
 */
const updateCarParkSpaceNumber = async () => {
  const _updateResult = await CfCarParkUtil.updateCarPark({
    id: carParkId.value,
    parkingSpaceNumber: formData.value.totalNum,
    usedParkingSpaceNumber: formData.value.usedNum,
  });
  if(_updateResult.code == 10002){

  }else{

  }
};

onMounted(() => {

});
onLoad((params) => {
  if(params != undefined) {
    carParkId.value = params.id;
    getCarParkInfo();
  }
});
</script>

